﻿using System;
using System.Linq;

public class Graph
{
    private int[,] nodes;
    private bool[] isVisited;
    private int minimalSum;
    private int currentSum;
    private int[] minimalCycle;
    private int[] cycle;

    public Graph(int[,] nodes)
    {
        this.nodes = nodes;
        this.isVisited = new bool[nodes.GetLength(0)];
        this.minimalSum = int.MaxValue;
        this.currentSum = 0;
        this.minimalCycle = new int[nodes.GetLength(0)];
        this.cycle = new int[nodes.GetLength(0)];
        this.cycle[0] = 1;
    }

    public int[] MinimalCycle
    {
        get
        {
            return minimalCycle;
        }
    }

    public int MinimalSum
    {
        get
        {
            return minimalSum;
        }
    }

    public void FindMinimalCycle()
    {
        FindMinimalCycle(0, 0);
    }

    private void FindMinimalCycle(int node, int level)
    {
        if (node == 0 && level > 0)
        {
            if (level == nodes.GetLength(0))
            {
                minimalSum = currentSum;
                for (int i = 0; i < nodes.GetLength(0); i++)
                {
                    minimalCycle[i] = cycle[i];
                }
            }
            return;
        }

        if (isVisited[node])
        {
            return;
        }

        isVisited[node] = true;
        for (int i = 0; i < nodes.GetLength(0); i++)
        {
            if (nodes[node, i] > 0 && i != node)
            {
                cycle[level] = i;
                currentSum += nodes[node, i];
                if (currentSum < minimalSum)
                {
                    FindMinimalCycle(i, level + 1);
                }
                currentSum -= nodes[node, i];
            }
        }
        isVisited[node] = false;
    }
}

public class Program
{
    static void Main(string[] args)
    {
        Graph graph = new Graph(ReadGraph());

        graph.FindMinimalCycle();

        if (graph.MinimalSum < int.MaxValue)
        {
            PrintCycle(graph.MinimalCycle);
            Console.WriteLine(graph.MinimalSum);
        }
        else
        {
            Console.WriteLine("No");
        }

    }

    static void PrintCycle(int[] minimalCycle)
    {
        // Print minimal Hamilton cycle in format {start node1 node2 ... end}
        Console.Write("{0} ", minimalCycle[0] + 1);
        for (int i = 1; i < minimalCycle.Length; i++)
        {
            Console.Write("{0} ", minimalCycle[i] + 1);
        }
        Console.WriteLine("{0}", minimalCycle[0] + 1);
    }

    static int[,] ReadGraph()
    {
        // Read graph as weighted adjacency matrix
        string input = Console.ReadLine();
        int N = int.Parse(input);

        int[,] graph = new int[N, N];
        for (int i = 0; i < N; i++)
        {
            input = Console.ReadLine();
            string[] rowElements = input.Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            for (int j = 0; j < N; j++)
            {
                graph[i, j] = int.Parse(rowElements[j]);
            }
        }

        return graph;
    }
}

